/*-
 * Copyright notice
 * 
 * (c) 2011 Christian Würtz <christian.wuertz@googlemail.com>
 * 
 * All rights reserved.
 * 
 * This file is part of the google-static-map-url-builder project. It is free
 * software: you can redistribute it and/or modify it under the terms of the 
 * GNU General Public License as published by the Free Software Foundation,
 * either version 2 of the License, or (at your option) any later version.
 * 
 * The google-static-map-url-builder is distributed in the hope that it will be
 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General 
 * Public License for more details.
 *  
 * You should have received a copy of the GNU General Public License
 * along with the google-static-map-url-builder. If not, see 
 * <http://www.gnu.org/licenses/>.
 */
package de.wuertz.map.types;

import java.text.DecimalFormat;

/**
 * This represents a GPS coordinate in decimal degree representation.
 * 
 * @author Christian Würtz <christian.wuertz@googlemail.com>
 */
public class Coordinate
{
	/**
	 * The format for a string representation of a latitude or longitude of a coordinate. It needs
	 * six zeros after the comma, because Google's Static Maps API doesn't allow a more accurate
	 * representation.
	 */
	public static final DecimalFormat COORDINATE_FORMAT = new DecimalFormat( "0.000000" );

	/**
	 * The latitude of this coordinate.
	 */
	private double latitude;

	/**
	 * The longitude of this coordinate.
	 */
	private double longitude;

	/**
	 * Creates a new coordinate.
	 * 
	 * @param latitude The latitude.
	 * @param longitude The longitude.
	 */
	public Coordinate( double latitude, double longitude )
	{
		this.latitude = latitude;
		this.longitude = longitude;
	}

	/**
	 * Get the latitude.
	 * 
	 * @return The latitude.
	 */
	public double getLatitude()
	{
		return this.latitude;
	}

	/**
	 * Set the latitude.
	 * 
	 * @param latitude The latitude to set.
	 */
	public void setLatitude( double latitude )
	{
		this.latitude = latitude;
	}

	/**
	 * Get the longitude.
	 * 
	 * @return The longitude.
	 */
	public double getLongitude()
	{
		return this.longitude;
	}

	/**
	 * Set the longitude.
	 * 
	 * @param longitude The longitude to set.
	 */
	public void setLongitude( double longitude )
	{
		this.longitude = longitude;
	}

	/**
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString()
	{
		// Use builder with size the latitude (10 characters), longitude (10 characters) and one comma
		// (1 character) can maximal have.
		StringBuilder builder = new StringBuilder( 21 );
		builder.append( COORDINATE_FORMAT.format( this.latitude ) );
		builder.append( "," );
		builder.append( COORDINATE_FORMAT.format( this.longitude ) );

		return builder.toString();
	}
}
